
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:Initialize()
	
	self:SetModel("models/props/cs_italy/orange.mdl")
	self.Dead = false
	self.Kill = CurTime() + 4
	
	self.Entity:PhysicsInitSphere( 15, "rubber" )
	
	local phys = self:GetPhysicsObject()
	if phys:IsValid() then
		phys:Wake()
	end
	
	self.Entity:SetCollisionBounds( Vector( -15, -15, -15 ), Vector( 15, 15, 15 ) )
	self:StartMotionController()
end

function ENT:Think()
	if self.Dead or self.Kill < CurTime() then
		self:Remove()
	end
end

function ENT:PhysicsSimulate(phys, frametime)
	phys:Wake()
	if self.Dead then return SIM_NOTHING end
	if self.Forward then
		phys:ApplyForceCenter(self.Barfer:GetAimVector() * 250 + Vector(0,0,75))
		self.Forward = false
	end
end

function ENT:SetBarfer(ply)
	if not ply:IsValid() or ply == NULL then return end 
	self.Barfer = ply
	local phys = self:GetPhysicsObject()
	if phys:IsValid() then
		self.Forward = true
	end	
end

function ENT:PhysicsCollide( data, phys )
	if data.Speed > 10 and data.DeltaTime > 0.2 then
		if math.random(1,2) == 1 then
			self:EmitSound(ChooseRandom(GameSounds.Slime),100,math.random(90,110))
		end
		if data.HitEntity then
			if data.HitEntity:IsValid() then
				if data.HitEntity:IsPlayer() then
					if data.HitEntity:Team() == TEAM_HUMANS then
						data.HitEntity:DoPoison()
					elseif data.HitEntity != self.Barfer then
						data.HitEntity:AddHealth(2)
					end
				end
			end
		end
		self.Dead = true
	end
end
